package dao

import (
	"FeedXmh/app/model"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/os/glog"
	"github.com/gogf/gf/util/gconv"
)

func GetMaxDaddr(mode string) (daddr uint32) {
	var startAddr uint32
	if mode == model.GW_MODE {
		startAddr = 20000000
	}
	db := g.DB(g.Cfg().GetString("custom.db_name"))
	var sql string
	sql = "SELECT max(daddr) as daddr FROM t_allocate_device where type='" + mode + "'"
	recode, err := db.GetOne(sql)
	if err != nil {
		glog.Println(err.Error())
		daddr = startAddr
	} else if recode == nil {
		daddr = startAddr
	} else {
		daddr = gconv.Uint32(recode.Map()["daddr"])
	}

	if daddr == 0 {
		daddr = startAddr
	}

	return daddr
}
